import http from '@/utils/axios'
import type {
  WebConfigType,
  HomeConfigType,
  AboutConfigType,
  CourseType,
  SignUpCourseType,
  LoginType,
  LoginResponseType,
  UserInfoType,
  EditUserInfoType,
  LibraryCateType,
  LibraryBookRequestType,
  LibraryBookResponseType,
  LibraryBookDetailType,
} from './type'

// 获取网站配置
export const webConfigApi = (): Promise<WebConfigType> => {
  return http({
    url: '/index/setting/index',
    method: 'GET',
  })
}

// 获取首页配置
export const homeConfigApi = (): Promise<HomeConfigType> => {
  return http({
    url: '/index/index/index',
    method: 'GET',
  })
}

// 获取关于我们配置
export const aboutConfigApi = (): Promise<AboutConfigType> => {
  return http({
    url: '/index/aboutus/index',
    method: 'GET',
  })
}

// 获取课程配置
export const courseConfigApi = (): Promise<CourseType[]> => {
  return http({
    url: '/index/course/index',
    method: 'GET',
  })
}

// 报名课程
export const signUpCourseApi = (data: SignUpCourseType): Promise<void> => {
  return http({
    url: '/index/course/sign_up',
    method: 'POST',
    data,
  })
}

// 登录
export const loginApi = (data: LoginType): Promise<LoginResponseType> => {
  return http({
    url: '/member/login/login',
    method: 'POST',
    data,
  })
}

// 获取用户信息
export const userInfoApi = (): Promise<{ data: UserInfoType }> => {
  return http({
    url: '/member/personal/material',
    method: 'GET',
  })
}

// 编辑用户信息
export const editUserInfoApi = (data: EditUserInfoType): Promise<void> => {
  return http({
    url: '/member/personal/changeInfo',
    method: 'POST',
    data,
  })
}

// 图书馆 -- 分类
export const libraryCateApi = (): Promise<{ data: LibraryCateType[] }> => {
  return http({
    url: '/index/book/category',
    method: 'GET',
  })
}

// 图书馆 -- 图书列表
export const libraryBookListApi = (
  params: LibraryBookRequestType,
): Promise<LibraryBookResponseType> => {
  return http({
    url: '/index/book/index',
    method: 'GET',
    params,
  })
}

// 图书馆 -- 图书详情
export const libraryBookDetailApi = (id: string): Promise<LibraryBookDetailType> => {
  return http({
    url: '/index/book/info',
    method: 'GET',
    params: {
      id,
    },
  })
}

// ! 未完成 ↓
// 获取学生作业列表
export const studentHomeworkListApi = (params: { page: number }): Promise<void> => {
  return http({
    url: '/member/student/get_homework_list',
    method: 'GET',
    params: {
      ...params,
      page_size: 10,
    },
  })
}

// 学生上传作业
export const studentUploadHomeworkApi = (data: FormData): Promise<void> => {
  return http({
    url: '/member/student/add_homework',
    method: 'POST',
    data,
  })
}
